package project.platform;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;

import project.Animal;
import project.platform.http.*;
import project.platform.mms.*;

/** 
 *  The central class of the communications platform.
 *  All the actual methods are defined in the subpackages.
 *  This class is used to provide an easy interface to 
 *  those subpackages to ease things for the linkage
 *  of the communications platform to the GUI.
 *  
 *  @author Paul Magrath - 05379725
 */
public class Platform{
	/** Web address of the servlet. */
	private static final String servletURL = "http://www.netsoc.tcd.ie/~pmagrath/tomcat/2ba7/";
	
	/** Method to send an animal to the servlet.
	 * @param a Animal to send.
	 * @param to The name of the user the servlet is to give it to.
	 * @param myID The current user's unique identifier.
	 * @return True or False depending on Success or Failure.
	 */
	public static boolean sendToServer(final Animal a, final String to, final String myID){
		return DataPlatform.sendToServer(a, to, myID, Platform.servletURL);
	}
	
	/** Method to download animals from the servlet 
	 * @param myID The current user's unique identifier
	 * @return The Animals received from the servlet 
	 * Note: 	Objects used for Java 1.4 optimization. 
	 * 			If using Java 5+, change to Animal objects.
	 */
	public static Object[] receiveFromServer(final String myID){
		return DataPlatform.receiveFromServer(myID, Platform.servletURL);
	}
	
	/** 
	 * Method to send an animal by MMS to another phone
	 * @param address Phone number in URL format e.g. mms://+5550001
	 * @param a The Animal to send to another phone
	 * @param sendingAlert an Alert to use for status
	 * @param errorAlert an Alert to use for errors
	 * @param appID This application's MMS application ID
	 * @param display Display that is being used
	 */
	public static void sendByMMS(String address, Animal a, Alert sendingAlert,
			Alert errorAlert, String appID, Display display){
		MMSPlatform.sendByMMS(address, a, sendingAlert, errorAlert, appID, display);
	}

	/** 
	 * Method to receive an animal by MMS from another phone.
	 * Starts a listener and then waits.
	 * 
	 * @param appID This application's MMS application ID
	 * @param display Display that is being used
	 * @param form Form that is being used
	 */
	public static void receiveMMS(String appID, Display display, Form form) {
		MMSPlatform.receiveMMS(appID, display, form);
	}
	
	/**
	 * Method to get animals received by MMS by thread started in receiveMMS()
	 * 
	 * @return The Animals received by MMS
	 */
	public static Animal[] getMMS(){
		return MMSPlatform.getFromMMS();
	}
	
}
